﻿using System.Diagnostics;
using System.Windows;

namespace 回调方法
{
    public partial class MainWindow : Window
    {
        public delegate void Callback(string mess);

        // public event Callback WpfCallback;
        public event Callback WpfCallback;

        private static int Number = 0;

        public string FCallback(string number, Callback callback)
        {
            callback(number);
            return number;
        }

        public MainWindow()
        {
            InitializeComponent();

            // 事件方式
            this.WpfCallback += MainWindow_WpfCallback;
        }

        private void MainWindow_WpfCallback(string mess)
        {
            Debug.WriteLine("[INFO] " + "Callback: " + mess);
        }

        private void btn_Click(object sender, RoutedEventArgs e)
        {
            Callback callback = (mess) =>
            {
                Debug.WriteLine("[INFO] " + mess);
            };

            FCallback(Number++.ToString(), callback);

            // 事件方式
            // WpfCallback?.Invoke(Number++.ToString());
        }
    }
}
